from parse.symbol_table.variable import Variable
from lexer.token.token import Token
from lexer.token.char import Char
from lexer.token.string import String
from lexer.token.number import Number
from lexer.token.token_type import TokenType

class ConstantVariable(Variable):
    def __init__(self, token: Token):
        super(ConstantVariable, self).__init__()

        if isinstance(token, Char):
            self.setType(TokenType.CHAR)
            self.name = "<char>"    # 类型作为名字
            self.value = token.value
        elif isinstance(token, Number):
            self.setType(TokenType.NUMBER)
            self.name = "<int>"    # 类型作为名字
            self.value = token.value
        elif isinstance(token, String):
            self.setType(TokenType.STRING)
            # TODO 源代码里面用了genLb的方法，待考察
            self.name = "<char>"    # 类型作为名字
            self.value = token.value
        else:
            raise Exception("不是常量")
